import Vue from 'vue'
import Router from 'vue-router'
// import Login from './components/login.vue'
const Login = () => import(/* webpackChunkName:"login_home_welcome" */ './components/login.vue')
// import Home from './components/home.vue'
// import wellcome from './components/subComponent/wellcome.vue'
const Home = () => import(/* webpackChunkName:"login_home_welcome" */ './components/home.vue')
const wellcome = () => import(/* webpackChunkName:"login_home_welcome" */ './components/subComponent/wellcome.vue')
// import users from './components/subComponent/users.vue'
// import roles from './components/subComponent/power/roles.vue'
// import rights from './components/subComponent/power/rights.vue'
const users = () => import(/* webpackChunkName:"users_rights_roles" */ './components/subComponent/users.vue')
const roles = () => import(/* webpackChunkName:"users_rights_roles" */ './components/subComponent/power/roles.vue')
const rights = () => import(/* webpackChunkName:"users_rights_roles" */ './components/subComponent/power/rights.vue')

// import cate from './components/subComponent/goods/cate.vue'
// import params from './components/subComponent/goods/params.vue'
const cate = () => import(/* webpackChunkName:"cate_params" */ './components/subComponent/goods/cate.vue')
const params = () => import(/* webpackChunkName:"cate_params" */ './components/subComponent/goods/params.vue')

// import goodsList from './components/subComponent/goods/goodsList.vue'
// import add from './components/subComponent/goods/add.vue'
const goodsList = () => import(/* webpackChunkName:"goodsList_add" */ './components/subComponent/goods/goodsList.vue')
const add = () => import(/* webpackChunkName:"goodsList_add" */ './components/subComponent/goods/add.vue')

// import order from './components/subComponent/order/order.vue'
// import report from './components/subComponent/reports/report.vue'
const order = () => import(/* webpackChunkName:"order_report" */ './components/subComponent/order/order.vue')
const report = () => import(/* webpackChunkName:"order_report" */ './components/subComponent/reports/report.vue')

Vue.use(Router)

const router = new Router({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', component: Login },
    { path: '/home',
      component: Home,
      children: [
        { path: '/home', redirect: '/wellcome'},
        { path: '/wellcome', component: wellcome},
        { path: '/users', component: users },
        { path: '/roles', component: roles },
        { path: '/rights', component: rights },
        { path: '/categories', component: cate },
        { path: '/params', component: params },
        { path: '/goods', component: goodsList },
        { path: '/goods/add',component: add },
        { path: '/orders', component: order },
        { path: '/reports', component: report }
      ]
    }
  ]
})
//挂载路由导航守卫
router.beforeEach((to,from,next)=>{
  if(to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/login')
  next()
})
export default router